//给定一个链表，删除链表的倒数第 n 个节点，并且返回链表的头结点。

//===========================通过 三个点 记录 一边扫描 通过



/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) 
    {
        if(!head)
            return NULL;
        
        ListNode * preNode = 0,*currNode = head,* forwardNode =head;
        for(int i=0;i<n ;i++)
        {
            forwardNode = forwardNode->next;
        }
        while(forwardNode)
        {
            preNode = currNode;
            currNode = currNode ->next;
            forwardNode = forwardNode->next;
        }
        if(preNode)
            preNode ->next = currNode->next;
        else
        {
            head = currNode->next;
        }
        return head;
        
    }
};